clear all
set type double
set varabbrev on, perm

*** FILL IN MAIN PATH TO RUN CODE ***
global dropbox "..."

global folder "$dropbox/_0_bjps_replication"
global in "$folder/in"
global out "$folder/out"
global proc "$folder/proc"

global graph "$out/graph"
global table "$out/table"
global temp "`c(tmpdir)'"
**************************
u "$proc/survey_reg_base.dta", clear

egen median_income = median(total_income)

g high_i = total_income >= median_income if total_income != 0
g low_i = total_income < median_income if total_income != 0

g college = education_level2 >= 5 if education_level2 != 0
g no_college = education_level2 < 5 if education_level2 != 0

g high_i_low_edu = high_i*no_college
g high_i_high_edu = high_i*college
g low_i_low_edu = low_i*no_college
g low_i_high_edu = low_i*college

g cat = ""
foreach v of varlist high_i_* low_i_* {
	replace cat = "`v'" if `v' == 1
}

gen cat_encode = .
replace cat_encode = 2 if cat == "high_i_low_edu"
replace cat_encode = 4 if cat == "high_i_high_edu"
replace cat_encode = 1 if cat == "low_i_low_edu"
replace cat_encode = 3 if cat == "low_i_high_edu"

label define cat_labels 2 "high_i_low_edu" 4 "high_i_high_edu" 1 "low_i_low_edu" 3 "low_i_high_edu"
label values cat_encode cat_labels
sa "$temp/before collapse", replace

replace count = weight if !mi(weight)
collapse (rawsum)count, by(cat_encode employer_SBO single_SBO)
drop if mi(cat_encode)
bysort single_SBO employer_SBO: egen tot = total(count)
g pct = count/tot

u "$temp/before collapse", clear
g republican = pid > 0.4 if !mi(pid)
g hile = cat_encode == 2
collapse (mean)republican trump [pweight = weight], by(hile)
